package com.itSession.cn.util;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

public class FileUtil {



    public static String upload(MultipartFile file) throws IllegalStateException, IOException {
        String path = PropUtil.getProperty("path");
        //获取文件名称
       String fileName = file.getOriginalFilename();
       //当前时间字符串
        String s = CommonseUtils.nowTime();
        //获取最后一个“.”的下标
        int i = fileName.lastIndexOf(".");
        //截取后缀
        String substring = fileName.substring(i);
        //拼接字符串
        fileName =s + CommonseUtils.tool(5) + "." + substring;
        //文件生成
        File tempFile = new File(path, fileName);
        //写入
        file.transferTo(tempFile);
        return fileName;
    }
}